
package JET.graphics.elements;

import JET.geom.Vec2d;
import JET.graphics.GraphicPanel;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;

/**
 *
 * @author raos
 */
public class DrawableLabel implements SceneDrawable {
    public double x=0, y=0;
    
    public Color color = Color.BLACK;
    public String text = "Label";

    private Font font = null;
    private int fontSize = 1;

    public DrawableLabel(String t, double x, double y) {
        this.text = t;
        this.x = x;
        this.y = y;
    }

    public DrawableLabel(String t, double x, double y, Font f) {
        this.text = t;
        this.x = x;
        this.y = y;
        this.setFont(f);
    }

    public DrawableLabel(String t, Vec2d pos) {
        this.text = t;
        this.x = pos.x;
        this.y = pos.y;
    }

    public void draw(Graphics g, GraphicPanel gp) {
        double x = gp.engineToScrX( this.x );
        double y = gp.engineToScrY( this.y );

        Graphics2D g2d = (Graphics2D)g;
        g.setColor(color);

        if (font!=null) {
            font = new Font(font.getName(), font.getStyle(), (int)(fontSize*gp.getViewScale()));
            g2d.setFont(this.font);
        }
        g2d.drawString(text, (float)x, (float)y);
    }

    public void setFont(Font f) {
        this.font = f;
        this.fontSize = f.getSize();
    }
}
